<template>
	<view class="container">
		<view class="update">
			<view class="uni-form-item uni-column">
				<view class="title">设备名称:</view>
				<view class="uni-input-wrapper">
					<input class="uni-input" type="text" placeholder="" v-model="deviceName" disabled />
				</view>
			</view>
			<view class="uni-form-item uni-column">
				<view class="title">设备IMEI:</view>
				<view class="uni-input-wrapper">
					<input class="uni-input" type="text" placeholder="" v-model="deviceImei" disabled />
				</view>
			</view>
			<!-- 			<view class="uni-form-item uni-column">
				<view class="title">设备ID:</view>
				<view class="uni-input-wrapper">
					<input class="uni-input" type="text" placeholder="" v-model="deviceId" disabled/>
				</view>
			</view> -->
			<view class="uni-form-item uni-column">
				<view class="title">姓名:</view>
				<view class="uni-input-wrapper">
					<input class="uni-input" type="text" placeholder="请输入绑定人姓名" v-model="elderNameNew" />
				</view>
			</view>
			<view class="uni-form-item uni-column">
				<view class="title">身份证号:</view>
				<view class="uni-input-wrapper">
					<input class="uni-input" type="idcard" placeholder="请输入绑定人身份证号码" v-model="elderIDNew" />
				</view>
			</view>
		</view>
		<button type="primary" style="width:200rpx; marginTop:20px;" @click="submitUpdate">提交</button>
	</view>
</template>

<script>
	import {
		updateBinding
	} from '@/pages/homepage/PillBox/api/pillbox.js'
	export default {
		data() {
			return {
				// 设备信息
				deviceName: '智能药盒',
				deviceID: 'ed6f1b73f1c545338b8190e1490f9436',
				deviceImei: '862170067052843',
				// 新的绑定人信息
				elderNameNew: '',
				elderIDNew: '',
			}
		},
		methods: {
			async submitUpdate() {
				console.log("更新绑定人信息");
				const data = {
					oldManName: this.elderNameNew,
					idNumber: this.elderIDNew,
					id: this.deviceID,
				}
				const res = await updateBinding(data);
				console.log("res",res)
				if (res.code===200){
					uni.showToast({
						icon:"none",
						title:res.msg,
						duration:2600,
					})
					setTimeout(()=>{
						uni.navigateTo({
							url:'/pages/homepage/ElderDeviceList/index'
						})
						console.log("back")
					},2600)
				}
			}
		},
		onLoad(options) {
			console.log(options)
			this.deviceName = options.deviceName;
			this.deviceID = options.deviceID;
			this.deviceImei = options.deviceImei;
		}
	}
</script>

<style>
	@import url(@/common/uni.css);

	view {
		font-size: 16px;
	}

	.uni-input-wrapper {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		padding: 8px 13px;
		flex-direction: row;
		flex-wrap: nowrap;
		background-color: #FFFFFF;
		/* added */
		width: auto;
		margin: 0 20rpx;
		border-radius: 5px;
	}

	.uni-input {
		height: 28px;
		line-height: 28px;
		font-size: 15px;
		padding: 0px;
		flex: 1;
		background-color: #FFFFFF;
	}
</style>